package cn.e4j.modular.api.service;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.modular.api.mapper.Bfjltb1Mapper;
import cn.e4j.modular.api.mapper.Gwat161Mapper;
import cn.e4j.modular.crm.entity.GwbnT;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by wenchuan.li on 2019/3/25.
 */

@Service
public class Bfjltb1Service{


    @Autowired
    Bfjltb1Mapper bfjltb1Mapper;

    @Autowired
    Gwat161Mapper gwat161Mapper;


    /**
     * 拜访记录提报作业--获取拜访记录列表
     *
     * @param inDto
     * @return
     * @author wenchuan.li on 2019/03/25 09:45
     */
    @Transactional(readOnly = true)
    public List<Dto> getBfjltb1List(Dto inDto) {
        return bfjltb1Mapper.getBfjltb1List(inDto);
    }

    /**
     * 拜访记录--新增
     *
     * @param gwbn_tPO
     * @return
     * @author wenchuan.li on 2018/06/14 12:13
     */
    @Transactional
    public void bfjltb1Add(GwbnT gwbn_tPO) {

        gwbn_tPO.insert();

    }

    /**
     * 根据客户获取商机拜访最大序号
     *
     * @param inDto
     * @return
     */
    @Transactional(readOnly = true)
    public List<Dto> getGwbnseqMax(Dto inDto) {
        return bfjltb1Mapper.getGwbnseqMax(inDto);
    }


    /**
     * 拜访记录--修改
     *
     * @param gwbn_tPO
     * @return
     * @author wenchuan.li on 2018/07/18 11:34
     */
    @Transactional
    public void bfrPage01Edit(GwbnT gwbn_tPO) {
        //WHERE  gwbnent = #{gwbnent} AND gwbnid = #{gwbnid} AND gwbnseq = #{gwbnseq}
        UpdateWrapper<GwbnT> gwbnTQueryWrapper = new UpdateWrapper<>();
        gwbnTQueryWrapper.eq("GWBNENT",gwbn_tPO.getGWBNENT());
        gwbnTQueryWrapper.eq("GWBNID",gwbn_tPO.getGWBNID());
        gwbnTQueryWrapper.eq("GWBNSEQ",gwbn_tPO.getGWBNSEQ());
        gwbn_tPO.update(gwbnTQueryWrapper);
    }


    /**
     * 删除拜访记录
     *
     * @param inDto
     * @return
     */
    @Transactional
    public void delBfjl(Dto inDto) {
        QueryWrapper<GwbnT> gwbnTQueryWrapper = new QueryWrapper<>();
        gwbnTQueryWrapper.eq("GWBNENT",inDto.getString("GWBNENT"));
        gwbnTQueryWrapper.eq("GWBNID",inDto.getString("GWBNID"));
        gwbnTQueryWrapper.eq("GWBNSEQ",inDto.getString("GWBNSEQ"));
        new GwbnT().delete(gwbnTQueryWrapper);
    }


    /**
     * 获取客户列表
     * <p>
     * 1.最终客户、2.经销商、3.内部法人、4.其他类
     *
     * @param inDto
     * @return
     * @author wenchuan.li on 2018/07/10 13:53
     */
    @Transactional(readOnly = true)
    public List<Dto> getGwakList(Page<Object>page,Dto inDto) {
        return bfjltb1Mapper.getGwakPage(page,inDto);
    }

}
